package com.sf.guava.collect;

import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;

import java.util.Iterator;
import java.util.Set;

/**
 * @Classname MultisetTest
 * @Description 处理重复元素 多线程测试
 * @Date 2019/12/11 0011 17:13
 * @Created by 埔枘
 */
public class MultisetThreadTest {

    public static void main(String[] args) {
        //创建 重复元素的集合
        //线程不安全
        Multiset<Integer> multiset = HashMultiset.create();
        new Thread(){
            @Override
            public void run() {
                for(int i=0;i<100;i++){
                    multiset.add(i);
                }
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                for(int i=100;i<200;i++){
                    multiset.add(i);
                }
            }
        }.start();

        print(multiset);
    }

    private static void print(Multiset<Integer> multiset) {
        for (Multiset.Entry entry : multiset.entrySet()){
            System.out.println("print:' : "+entry.getElement()+"-----"+entry.getCount());
        }
    }

}
